package com.lc.user.express.httpserver;

import com.lc.user.express.app.AppContext;
import com.lc.user.express.model.FurnitureModel;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/31.家居商品列表
 */
@HttpInlet(Net.GET_GOODS)
public class GetGoods extends ZJDBAsyGet<GetGoods.Info> {
    public String typeid;
    public int page;

    public GetGoods(String typeid,int page,AsyCallBack listener) {
        super(listener);
        this.typeid = typeid;
        this.page = page;

    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            JSONArray array = object.optJSONArray("list");
            info.ispage = object.optInt("ispage");
            info.nextpage = object.optInt("nextpage");

            if(array != null){
                for (int i = 0; i<array.length(); i++){
                    JSONObject jsonObject = array.optJSONObject(i);
                    FurnitureModel model = new FurnitureModel();
                    model.setName(jsonObject.optString("title"));
                    model.setId(jsonObject.optString("id"));
                    model.setPicUrl(Net.SERVER + jsonObject.optString("picurl"));
                    info.dataList.add(model);
                }

            }
            return info;
        }
        return null;
    }

    public static class Info {
        public List<FurnitureModel> dataList = new ArrayList<>();
        public int ispage;
        public int nextpage;

    }
}
